package com.company.eduservice.controller;


import com.company.eduservice.entity.EduChapter;
import com.company.eduservice.service.EduChapterService;
import com.company.eduservice.vo.chapter.ChapterVo;
import com.company.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-04-18
 */
@RestController
@RequestMapping("/eduservice/chapter")
@CrossOrigin
public class EduChapterController {

    @Resource
    private EduChapterService eduChapterService;

    //根据课程ID查询所有查找大纲列表
    @GetMapping("/getChapterVideo/{courseId}")
    public R getChapterVideo(@PathVariable String courseId) {
        List<ChapterVo> list = eduChapterService.getChapterVideoByCourseId(courseId);
        return R.ok().data("allChapterVideo", list);
    }

    //添加课程大纲的章节
    @PostMapping("/addChapter")
    public R addChapter(@RequestBody EduChapter eduChapter){
        eduChapterService.addChapterByCourse(eduChapter);
        return R.ok();
    }

    //根据章节ID查询章节
    @GetMapping("/getChapterInfo/{chapterId}")
    public R getChapterInfo(@PathVariable String chapterId){
        EduChapter eduChapter = eduChapterService.findChapterById(chapterId);
        return R.ok().data("chapter", eduChapter);
    }

    //修改课程大纲的章节
    @PostMapping("/updateChapter")
    public R updateChapter(@RequestBody EduChapter eduChapter){
        eduChapterService.updateChapter(eduChapter);
        return R.ok();
    }

    //删除章节
    @DeleteMapping("/{chapterId}")
    public R deleteChapter(@PathVariable String chapterId){
        eduChapterService.deleteChapterById(chapterId);
        return R.ok();
    }
}

